#######################################################################################################################
# File Name  : Makefile.RH850.GHS.GHS.LinkerScriptDefault                                                             #
# Description: Default Linker/Symbol Preprocessor command file generation                                             #
# Project    : Vector Basic Runtime System                                                                            #
# Module     : BrsHw for Platform Renesas RH850                                                                       #
#              and Compiler GreenHills                                                                                #
#                                                                                                                     #
#---------------------------------------------------------------------------------------------------------------------#
# COPYRIGHT                                                                                                           #
#---------------------------------------------------------------------------------------------------------------------#
# Copyright (c) 2017 by Vector Informatik GmbH.                                                  All rights reserved. #
#                                                                                                                     #
#---------------------------------------------------------------------------------------------------------------------#
# AUTHOR IDENTITY                                                                                                     #
#---------------------------------------------------------------------------------------------------------------------#
# Name                          Initials      Company                                                                 #
# ----------------------------  ------------  ------------------------------------------------------------------------#
# Steffen Frank                 visfsn        Vector Informatik GmbH                                                  #
# Benjamin Walter               visbwa        Vector Informatik GmbH                                                  #
# Jan Lutterbeck                visljn        Vector Informatik GmbH                                                  #
# David Feuerstein              visdfe        Vector Informatik GmbH                                                  #
#---------------------------------------------------------------------------------------------------------------------#
# REVISION HISTORY                                                                                                    #
#---------------------------------------------------------------------------------------------------------------------#
# Version   Date        Author  Description                                                                           #
# --------  ----------  ------  --------------------------------------------------------------------------------------#
# 01.00.00  2014-06-10  visfsn  Initial version                                                                       #
# 01.01.00  2014-06-17  visfsn  Changed variable for memory mapping                                                   #
# 01.02.00  2014-07-30  visbwa  Adaptions for new BRS code structure                                                  #
# 01.02.01  2014-08-27  visljn  Linker labels for SDA optimization added                                              #
# 01.02.02  2014-09-02  visdfe  Added Data and Const Section for Mcal Fls Driver                                      #
# 01.03.00  2016-06-20  visbwa  adapted file header according to Brs_Template 2.00.01                                 #
# 01.04.00  2016-09-09  visbwa  Vectable separated, Makefile.RH850.GHS.GHS.LinkerScriptMultiCore introduced           #
# 01.04.01  2017-04-28  visbwa  Renamed LD_FILE_DEFAULT by LD_FILE directly                                           #
#######################################################################################################################

# Interrupt Vector Table base address for MasterCore
INTVECT_COREEXCEPTIONS_CORE0 = 0x00
INTVECT_EXTERNALINT_CORE0 =    0x200

#------------------------------------------------------------------------------
# rule to generate linker command file
#------------------------------------------------------------------------------

######################################################################################################################################################
# MAIN LINKER SCRIPT CODE
######################################################################################################################################################
define LD_FILE
  $(ECHO) "MEMORY"                                                                                                                         > $@; \
  $(ECHO) " {"                                                                                                                            >> $@; \
  $(MEMORY_ALLGROUPS)                                                                                                                            \
  $(ECHO) " }"                                                                                                                            >> $@; \
  $(ECHO) ""                                                                                                                              >> $@; \
  $(ECHO) "SECTIONS"                                                                                                                      >> $@; \
  $(ECHO) " {                                                                                                                           " >> $@; \
  $(ECHO) "  /*************************************************************************************************************************/" >> $@; \
  $(ECHO) "  /* ROM AREA (iROM_0A)*/                                                                                                    " >> $@; \
  $(ECHO) "  /*************************************************************************************************************************/" >> $@; \
  $(ECHO) "  .rom_start                               :>iROM_0A  /* Start of code area */                                               " >> $@; \
  $(ECHO) "  .intvect_CoreExceptions  $(INTVECT_COREEXCEPTIONS_CORE0)  :>.  /* start of Core interrupt vector table, from BRS */        " >> $@; \
  $(ECHO) "  .intvect                                                  :>.  /* start of interrupt vector table, used by OS */           " >> $@; \
  $(ECHO) "  .intvect_ExtExceptions   $(INTVECT_EXTERNALINT_CORE0)     :>.  /* start of External interrupt vector table, from BRS */    " >> $@; \
  $(ECHO) "  .eivect                                                   :>.  /* Second part of the interrupt table, used by OS */        " >> $@; \
  $(ECHO) "                                                                                                                             " >> $@; \
  $(ECHO) "  /* START OF CODE AREA */                                                                                                   " >> $@; \
  $(ECHO) "  .code_start                              :>.  /* Start of code area */                                                     " >> $@; \
  $(ECHO) "  .text                    align(4)        :>.  /* program code area */                                                      " >> $@; \
  $(ECHO) "  .os_text                 align(4)        :>.  /* program code area */                                                      " >> $@; \
  $(ECHO) "  .R_FDL_Text              align(4)        :>.  /* FDL code in ROM (used by MCAL) */                                         " >> $@; \
  $(ECHO) "  .MCU_CODE_RRAM_INTVEC    align(4)        :>.                                                                               " >> $@; \
  $(ECHO) "  .MCU_CR_CODE_RRAM        align(4)        :>.                                                                               " >> $@; \
  $(ECHO) "  .code_end                                :>.  /* End of code area */                                                       " >> $@; \
  $(ECHO) "  /* END OF CODE AREA */                                                                                                     " >> $@; \
  $(ECHO) "                                                                                                                             " >> $@; \
  $(ECHO) "  /* START OF CONST AREA */                                                                                                  " >> $@; \
  $(ECHO) "  .const_start                             :>.  /* start of const area */                                                    " >> $@; \
  $(ECHO) "  .rozdata                                 :>.  /* constant datas in ZDA area */                                             " >> $@; \
  $(ECHO) "  .rosda_start                             :>.  /* start of SDA data area */                                                 " >> $@; \
  $(ECHO) "  .robase                  align(4)        :>.  /* initialize textpointer TP for SDA addressing */                           " >> $@; \
  $(ECHO) "  .rosdata                 align(4)        :>.  /* constant datas in SDA area */                                             " >> $@; \
  $(ECHO) "  .os_rosdata              align(4)        :>.  /* constant OS data in SDA area */                                           " >> $@; \
  $(ECHO) "  .osConfigBlock_rodata    align(4)        :>.  /* constant OS ConfigBlock in SDA area */                                    " >> $@; \
  $(ECHO) "  .rosda_end                               :>.  /* end of SDA data area */                                                   " >> $@; \
  $(ECHO) "  .rodata                  align(4)        :>.  /* constant datas in normal area */                                          " >> $@; \
  $(ECHO) "  .R_FDL_Const             align(4)        :>.  /* constant datas for DrvFls */                                              " >> $@; \
  $(ECHO) "  .os_rodata               align(4)        :>.  /* constant OS data in normal area */                                        " >> $@; \
  $(ECHO) "  .const_end                               :>.  /* end of const area */                                                      " >> $@; \
  $(ECHO) "  /* END OF CONST AREA */                                                                                                    " >> $@; \
  $(ECHO) "                                                                                                                             " >> $@; \
  $(ECHO) "  .fixaddr                 align(4)        :>.  /* ghs internal (compiler) */                                                " >> $@; \
  $(ECHO) "  .fixtype                 align(4)        :>.  /* ghs internal (compiler) */                                                " >> $@; \
  $(ECHO) "  .secinfo                 align(4)        :>.  /* ghs internal (runtime library) */                                         " >> $@; \
  $(ECHO) "  .syscall                 align(4)        :>.  /* ghs internal (linker) */                                                  " >> $@; \
  $(ECHO) "                                                                                                                             " >> $@; \
  $(ECHO) "  .const_init_data_start                   :>.  /* start of const init data area */                                          " >> $@; \
  $(ECHO) "  .romdata                 ROM(.data)      :>.  /* init values for .data (copied to RAM at startup) */                       " >> $@; \
  $(ECHO) "  .romzdata                ROM(.zdata)     :>.  /* init values for .zdata (copied to RAM at startup) */                      " >> $@; \
  $(ECHO) "  .romsdata                ROM(.sdata)     :>.  /* init values for .sdata (copied to RAM at startup) */                      " >> $@; \
  $(ECHO) "  .romtdata                ROM(.tdata)     :>.  /* init values for .tdata (copied to RAM at startup) */                      " >> $@; \
  $(ECHO) "  .const_init_data_end                     :>.  /* end of const init data area */                                            " >> $@; \
  $(ECHO) "                                                                                                                             " >> $@; \
  $(ECHO) "  /*************************************************************************************************************************/" >> $@; \
  $(ECHO) "  /* RAM*/                                                                                                                   " >> $@; \
  $(ECHO) "  /*************************************************************************************************************************/" >> $@; \
  $(ECHO) "  .ram_start                               :>iRAM_CORE0  /* Start of RAM area of MasterCore */                               " >> $@; \
  $(ECHO) "                                                                                                                             " >> $@; \
  $(ECHO) "  /* START OF NORMAL DATA RAM AREA */                                                                                        " >> $@; \
  $(ECHO) "  .data                    align(4)        :>.  /* initialized data */                                                       " >> $@; \
  $(ECHO) "  .R_FDL_Data              align(4)        :>.  /* data for DrvFls */                                                        " >> $@; \
  $(ECHO) "  .bss                     align(4) CLEAR  :>.  /* zero initialized data */                                                  " >> $@; \
  $(ECHO) "  .os_data                                 :>.  /* initialized OS data */                                                    " >> $@; \
  $(ECHO) "  .os_bss                  align(4) CLEAR  :>.  /* zero initialized OS data */                                               " >> $@; \
  $(ECHO) "  /* END OF NORMAL DATA RAM AREA */                                                                                          " >> $@; \
  $(ECHO) "                                                                                                                             " >> $@; \
  $(ECHO) "  /* START OF SDA RAM AREA */                                                                                                " >> $@; \
  $(ECHO) "  .sda_start                               :>.  /* start of SDA RAM area */                                                  " >> $@; \
  $(ECHO) "  .sdabase                 align(4)        :>.  /* initialize globalpointer GP for SDA addressing */                         " >> $@; \
  $(ECHO) "  .sdata                   align(4)        :>.  /* initialized data in SDA area */                                           " >> $@; \
  $(ECHO) "  .sbss                    align(4) CLEAR  :>.  /* zero initialized data in SDA area */                                      " >> $@; \
  $(ECHO) "  .os_sdata                align(4)        :>.  /* initialized OS data in SDA area */                                        " >> $@; \
  $(ECHO) "  .os_sbss                 align(4) CLEAR  :>.  /* zero initialized OS data in SDA area */                                   " >> $@; \
  $(ECHO) "  .sda_end                                 :>.  /* end of SDA RAM area */                                                    " >> $@; \
  $(ECHO) "  /* END OF SDA RAM AREA */                                                                                                  " >> $@; \
  $(ECHO) "                                                                                                                             " >> $@; \
  $(ECHO) "  /* START OF STACK AREA */                                                                                                  " >> $@; \
  $(ECHO) "  .stack    align(4) pad(0x400)            :>.     /* definition of stack size */                                            " >> $@; \
  $(ECHO) "  /* END OF STACK AREA */                                                                                                    " >> $@; \
  $(ECHO) "                                                                                                                             " >> $@; \
  $(ECHO) "  .zdata                   align(4)                :>.  /* initialized data in ZDA area */                                   " >> $@; \
  $(ECHO) "  .zbss                    align(4) CLEAR          :>.  /* zero initialized data in ZDA area */                              " >> $@; \
  $(ECHO) "  .tdata                   align(4) MAX_SIZE(256)  :>.  /* initialized and zero-initialized data in TDA area */              " >> $@; \
  $(ECHO) "  .ram_end                 align(16)               :>.                                                                       " >> $@; \
  $(ECHO) "                                                                                                                             " >> $@; \
  $(ECHO) "  /*************************************************************************************************************************/" >> $@; \
  $(ECHO) "  /* LABELS*/                                                                                                                " >> $@; \
  $(ECHO) "  /*************************************************************************************************************************/" >> $@; \
  $(ECHO) " }                                                                                                                           " >> $@;
endef
